var loginVm = new Vue({
    el: '#loginContainer',
    data: {
        username: '',
        password: '',
        captcha: '',
        captchaUrl: '/captcha.jpg?t=' + $.now(),
        error: $('#errMsg').text()
    },
    methods: {
        refreshCaptcha: function () {
            this.captchaUrl = '/captcha.jpg?t=' + $.now(); //加时间戳，防止验证码缓存
        },
        login: function (event) {
            var hasError = false;

            if (this.username.length == 0) {
                hasError = true;
                this.error = '用户名不能为空';
            } else if (this.password.length == 0) {
                hasError = true;
                this.error = '密码不能为空';
            } else if (this.captcha.length == 0) {
                hasError = true;
                this.error = '验证码不能为空';
            }

            if (hasError)
                event.preventDefault();
        }
    }
});